package com.dhcc.hikari.util.thread.runnable;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.dhcc.hikari.controller.NrController;
import com.dhcc.hikari.entity.NurseRevocation;
import com.dhcc.hikari.excel.listener.DemoDataListener;
import com.dhcc.hikari.service.NurseRevocationService;
import com.dhcc.hikari.util.SpringUtil;

/**
 * <p>标题: MyRunnable.java</p>
 * <p>业务描述:区域预约挂号平台</p>
 * <p>公司:东华软件股份公司</p>
 * <p>版权:dhcc2013</p>
 * @author 胡凯
 * @date 2018年11月21日
 * @version V1.0 
 */
public class InsertNrsRunnable implements Runnable {
	private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class);
	private List<NurseRevocation> list;
	
	@Autowired
	private NurseRevocationService nurseRevocationService;
	@Autowired
	NrController nrController;
	long startTime =0;
	long endTime =0;
	long time =0;
	long totalTime = 0;
	int totalCount = 0;
	public InsertNrsRunnable(List<NurseRevocation> list) {
		super();
		this.list = list;
	}


	@Override
	public void run() {
		String name = Thread.currentThread().getName();
		System.out.println(name + " is working...");
		saveData();
	}
	private void saveData() {
        LOGGER.info("{}条数据，开始存储数据库！", list.size());
        nrController = (NrController)SpringUtil.getBean("nrController",NrController.class);
        int count = nrController.batchInsert(list);
        LOGGER.info("存储数据库成功！存储："+count+"个");
        endTime = System.currentTimeMillis();
        time = endTime-startTime;
        totalTime +=time; 
        totalCount +=count;
        System.out.println("每次存储数据时间："+time +"--耗时累加："+totalTime+"--累加数值："+totalCount);
    }
}
